package org.colcon.web.model;

import java.util.HashMap;
import java.util.Map;

import org.colcon.web.model.decision.NullDecision;
import org.colcon.web.model.framework.IDecision;
import org.colcon.web.model.framework.IProposal;
import org.colcon.web.model.framework.IVote;

public class Proposal extends Vote implements IProposal
{
	private static final long serialVersionUID = 5106024382467256721L;

	public static final String
	
		// arguments
		VOTE_LENGTH = "vote_length",
		VOTE_QUORUM = "vote_quorum";
	
	private int voteLength, voteQuorum;
	
	public Proposal()
	{
		this(new HashMap<String, String>());
	}
	
	public Proposal(Map<String, String> args)
	{
		//TODO: add proposal_type argument
		this(
				args.get(ID), 
				args.get(GROUP), 
				Integer.valueOf(args.get(LENGTH)), 
				Integer.valueOf(args.get(QUORUM)), 
				args.get(TITLES).split(" "),
				Integer.valueOf(args.get(VOTE_LENGTH)), 
				Integer.valueOf(args.get(VOTE_QUORUM))
		);
	}
	
	public Proposal(String group, String id, int length, int quorum, String[] titles, int voteLength, int voteQuorum) 
	{
		super(group, id, length, quorum, titles);
		
		this.voteLength = voteLength;
		this.voteQuorum = voteQuorum;
	}
	
	public int getVoteLength()
	{
		return voteLength;
	}
	
	public int getVoteQuorum()
	{
		return voteQuorum;
	}
	
	public IDecision getDecision()
	{
		IVote vote = getVote();
		
		if(vote == null)
			return new NullDecision(getGroup());
		
		//TODO: pass vote args
		return new Decision(getGroup(), "add groups/" + getGroup() + "/votes -type vote");
	}
	
	public IVote getVote()
	{
		return new Vote();
	}
}
